home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3418 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.4 KB  |  65 lines

  1. Path: pubxfer.news.psi.net !usenet
  2. From: dcomery.dynalog@LNN.COM (David Comery)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Operator Overloading question
  5. Date: 23 Jan 1996 20:12:37 GMT
  6. Organization: Dynalog Technologies
  7. Message-ID: <4e3ffl$58l@pubxfer2.news.psi.net>
  8. References: <Robert.Lendvai-2101960120380001@129.170.80.94>
  9. Reply-To: pspiro.dynalog@LNN.COM
  10. NNTP-Posting-Host: ftp.dynalog.com
  11. X-Newsreader: WinVN 0.92.6+
  12.  
  13. In article <Robert.Lendvai-2101960120380001@129.170.80.94>, Robert.Lendvai@dartmouth.edu (Robert Lendvai) says:
  14. >
  15. >Codewarrior is saying this:
  16. >
  17. >Error   : illegal 'operator' declaration
  18. >player.h line 23   friend Boolean operator == (Player * member, char *
  19. >dude); //Check to see if a player has this name
  20. >
  21. >about the following code, but I have no idea why. Can anyone help?
  22. >
  23. >
  24. >
  25. >#include <iostream.h>
  26. >#include <stdlib.h>
  27. >
  28. >class Player{
  29. >
  30. >private:
  31. >
  32. >
  33. >char * name;
  34. >int rating;
  35. >Player * next;
  36. >
  37. >public:
  38. >
  39. >Player(char * s);
  40. >Player();
  41. >~Player();
  42. >
  43. >
  44. >
  45. >
  46. >friend class Player_list;
  47. >friend Boolean operator == (Player * member, char * dude); //Check to see
  48. >if a                                             //player has this name
  49. >
  50. >};
  51.  
  52. You can avoid the problem altogether by making the ==operator 
  53. a member function of the class, instead of making it a friend function:
  54.  
  55. class Player
  56. {
  57. public:
  58. friend class Player_list;
  59. Boolean operator==( char * dude);
  60. };
  61.  
  62. this is the easist way, although the other way will work too.
  63.  
  64. -Pete Spiro
  65.